import time

import allure

from selenium.webdriver.common.by import By
from .base import Base
from .contact import Contact


class PageJumps(Base):  # 页面跳转
    __CONTACT_LINK = (By.CSS_SELECTOR, "nav.frame_nav > a:nth-child(2)")  # 通讯录按钮
    __CHECK_NAME = (By.ID, "memberSearchInput")     # 查询框
    __CHECK_NAME_PHONE_NUMBER = (By.CSS_SELECTOR, ".member_display_item.member_display_item_Phone "
                                                  "> .member_display_item_right")   # 查询的手机号

    def goto_contact(self):
        with allure.step("跳转到通讯录页面"):
            self.find_click(self.__CONTACT_LINK)
        return Contact(self.driver)

    def get_contact_member(self, member_name):
        with allure.step("查询部门人员"):
            time.sleep(1)   # 必须强制等待
            self.find_key(self.__CHECK_NAME, member_name)   # 使用 姓名 查询人员
            self.wait(method=self.__CHECK_NAME_PHONE_NUMBER)    # 显式等待
            self.images_log("check", "信息查询")  # 截图
            phone_number = self.find_text(self.__CHECK_NAME_PHONE_NUMBER)   # 获取查询 姓名的手机号
        return phone_number
